import Axios from 'axios'

// create an axios instance
const request = Axios.create({
  withCredentials: true, // send cookies when cross-domain requests
  timeout: 30000 // request timeout
})


// response interceptor
request.interceptors.response.use(
  /**
   * If you want to get http information such as headers or status
   * Please return  response => response
   */

  /**
   * Determine the request status by custom code
   * Here is just an example
   * You can also judge the status by HTTP Status Code
   */
  response => {
    console.log(response)
    return response
  },
  error => {
    const response = error.response
    console.log(response)
    // do something with request error
    if (response.status) {
      const result = response.data
      console.log(result)
      return Promise.reject(result) // 返回接口返回的错误信息
    }
    return Promise.reject(error)
  }
)

export default request
